<template>
  <div>
    <h1>hello</h1>
    <h1>{{count}}</h1>
    <button @click='byebye'>bye</button>
  </div>
</template>

<script>
import Pubsub from 'pubsub-js'

export default {
    name:'Hello',
    data(){
        return{
            //一般我们在接收发布信息之前,都要书写一个初始值
            count:0
        }
    },
    mounted(){
        //先订阅,一般在初始化环节就订阅 mounted
        Pubsub.subscribe('count',(_,count)=>{
            this.count=count
        })
    },
    methods:{
        byebye(){
            //unsubscribe参数如果是订阅名称,则直接取消当前名称的所有订阅
            Pubsub.unsubscribe('count')
        }
    }
}
</script>

<style>

</style>